package com.kongxx.freemarkstudy;

import java.io.File;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import com.kongxx.freemarkstudy.simple.Greeting;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;

public class FreeMarkerUtil {
	public static void process(Map rootMap, Class clazz, String template) 
		throws Exception {
		Configuration cfg = new Configuration();
		cfg.setClassForTemplateLoading(clazz, "");
		cfg.setObjectWrapper(new DefaultObjectWrapper());
		
		// Get the template
		Template temp = cfg.getTemplate(template); 
		
		// Merging the template with the data model
		Writer out = new OutputStreamWriter(System.out);
		temp.process(rootMap, out);
		out.flush();
	}
}
